<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8" />
    <title>扫码登录-{eyou:global name='web_name' /}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <link href="{eyou:global name='web_cmspath'/}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    {eyou:static file="/template/plugins/wxlogin/skin/css/basic.css" /}
    {eyou:static file="/template/plugins/wxlogin/skin/css/eyoucms.css" /}
    {eyou:include file="wxlogin/skin/css/diy_css.htm" /}

    {eyou:static file="/public/static/common/js/jquery.min.js"/}
    {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
    {eyou:static file="/template/plugins/wxlogin/skin/js/global.js" /}
</head>

<body class="reg regi">
<div class="register_index ey-member">
    <div class="container">
        <form name='theForm' id="theForm" method="post" class="form-register panel-body fv-form">
            <div class="mip-reg-logo"><a href="{eyou:global name='web_cmsurl' /}" class="ey-logo"><img src="{eyou:global name='web_logo'/}" /></a></div>
            <div class="" style="display: flex;justify-content: space-evenly;margin: 10px 0;">
                <label onclick="changepass(1)"><input name="type" type="radio" value="1" checked/> 注册新账号 </label>
                <label onclick="changepass(2)"><input name="type" type="radio" value="2"/> 绑定已有账号 </label>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <input type="text" name="username" required class="form-control" placeholder="用户名"/>
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <input type="password" name="password" required class="form-control" placeholder="登录密码"/>
                </div>
            </div>
	        <div id="confirm_pass">
	            <div class="form-group" >
	                <div class="input-group">
	                    <input type="password" name="password2" required class="form-control" placeholder="确认密码"/>
	                </div>
	            </div>
	            <!-- 更多资料中的会员属性 -->
	            {eyou:include file="wxlogin/users_reg_field.htm" /}
            </div>
            <!-- 结束 -->
            <input type="hidden" name="referurl" class="form-control" value="{$referurl}"/>
            <input type="hidden" name="wxid" class="form-control" value="{$wxid}"/>
            <input  type="button" onclick="checkUser();"  class="btn btn-lg btn-primary btn-block" value="提交"/>
        </form>
    </div>
</div>

<script type="text/javascript">
    $(document).keydown(function(event){
        if(event.keyCode ==13){
            checkUser();
            return false;
        }
    });

    function changepass(type){
    	if ( 1==type ) {
    		$("#confirm_pass").show();
    	}else if ( 2==type) {
    		$("#confirm_pass").hide();
    	}
    }

    function checkUser(){
    	var type = $("#theForm input[name='type']:checked").val();
        var username = $('#theForm input[name=username]');
        var password = $('#theForm input[name=password]');
        var password2 = $('#theForm input[name=password2]');
        var wxid = $('#theForm input[name=wxid]');

        if(username.val() == ''){
            layer.msg('请输入用户名！', {time: 1500, icon: 2});
            username.focus();
            return false;
        }

        if(password.val() == ''){
            layer.msg('请输入登录密码！', {time: 1500, icon: 2});
            password.focus();
            return false;
        }

        if (1==type && password2.val() == '') {
        	layer.msg('请输入确认密码！', {time: 1500, icon: 2});
            password2.focus();
            return false;
        }

		layer_loading('正在处理');
        $.ajax({
            url: "{eyou:url link='plugins/WxLogin/bind' /}",
            data: $('#theForm').serialize(),
            type:'post',
            dataType:'json',
            success:function(response){
            	console.log(response)
                layer.closeAll();
                var res = response.data;
                if(res.status == 2){
                //success
                	if (type==2) {
                		//bind
                		layer.msg(response.msg, {time: 1000,icon:1}, function(){
                        	window.location = response.url;
                    	});
                	}else{
                		//reg
                		window.location = response.url;
                	}
                }else if(res.status == 3){
                //is_activation
                	layer.msg(response.msg, {time: 1000,icon:2}, function(){
                        window.location = response.url;
                    });
                }else if(res.status == 1){
                //username
                    layer.msg(response.msg, {time: 2000,icon:2});
                    username.focus();
                }else if(res.status == 0){
                //password
                    layer.msg(response.msg, {time: 2000,icon:2});
                    password.focus();
                }else if(res.status == 4){
                    layer.msg(response.msg, {time: 2000,icon:2});
                    password.val('');
                    password2.val('');
                    password.focus();
                }else if(res.status == 5){
                    if (response.url) {
                    	layer.msg(response.msg, {time: 2000,icon:1}, function(){
                        	window.location = response.url;
                    	});
                    }else{
                    	layer.msg(response.msg, {time: 2000,icon:2});
                    }
                }
            },
            error : function() {
                layer.closeAll();
                layer.alert('网络失败，请刷新页面后重试', {icon: 5});
            }
        });
    };
</script>

</body>
</html>